package com.anrongtec.zcpt.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.adapter.common.MultiItemTypeAdapter;
import com.anrongtec.zcpt.adapter.common.ViewHolder;
import com.anrongtec.zcpt.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;
import com.lzy.okhttpserver.download.DownloadInfo;
import com.lzy.okhttpserver.download.DownloadManager;

import java.util.List;

/**
 * 作者：liuhui on 2017/2/15 16:34
 * 邮箱：liu594545591@126.com
 * 描述：AppDownManageAdapter
 */

public class AppDownManageAdapter extends MultiItemTypeAdapter<DownloadInfo>
        implements StickyRecyclerHeadersAdapter<ViewHolder> {
    public static final int STATUS_DOWNLOADING = 1;
    public static final int STATUS_DOWNLOADED = 2;

    public AppDownManageAdapter(Context context, List<DownloadInfo> datas) {
        super(context, datas);
    }

    @Override
    public long getHeaderId(int position) {
        DownloadInfo info = mDatas.get(position);
        if (info.getState() == DownloadManager.FINISH) {
            return STATUS_DOWNLOADED;
        }
        return STATUS_DOWNLOADING;
    }

    @Override
    public int getItemViewType(int position) {
        DownloadInfo info = mDatas.get(position);
        if (info.getState() == DownloadManager.FINISH) {
            return STATUS_DOWNLOADED;
        }
        return STATUS_DOWNLOADING;
    }

    @Override
    public void onBindHeaderViewHolder(ViewHolder holder, int position) {
        int viewType = getItemViewType(position);
        if (viewType == STATUS_DOWNLOADED) {
            holder.setText(R.id.tv_item_header_down_manager_name, "已下载");
            return;
        }
        holder.setText(R.id.tv_item_header_down_manager_name, "下载中");
    }

    @Override
    public ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        ViewHolder holder = ViewHolder.createViewHolder(mContext, parent,
                R.layout.item_header_down_manager);
        return holder;
    }

    // private class HeaderViewHolder extends ViewHolder {
    //
    // public HeaderViewHolder(Context context, View itemView) {
    // super(context, itemView);
    // }
    //
    // }

    // @Override
    // public int getItemCount() {
    // // TODO Auto-generated method stub
    // return mDatas.size();
    // }
}
